package com.cnzhy.lambda;

import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.stream.Stream;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.toList;

/**
 * @Author: zhaoyan5
 */
@SpringBootTest
public class LambdaTest {

    @Test
    public void labmda1() {
        String answer = "123";
        new Thread(() -> {
            // answer = "321"; 编译报错,lambda表达式不能修该表达式的外部变量
            System.out.println("The answer is: " + answer);
        }).start();
    }

    @Test
    public void labmda2() {
        List<String> list = Stream.of("a", "b", "hello").map(String::toUpperCase).collect(toList());
        Stream.of(list).forEach(item -> System.out.println(item));
    }

    @Test
    public void labmda3() {
        List<Integer> list = Stream.of(asList(1, 2), asList(3, 4)).flatMap(numbers -> numbers.stream()).collect(toList());
        Stream.of(list).forEach(System.out::println);
    }
}
